<?php

    require_once($application_folder."/controllers/navigator.php");
    class Nalog extends navigator 
    {
        function Nalog (){ 
            parent::navigator();
            $this->load->model('nalog_m', 'nalog');
        }
        public function index(){
            $this->data['strana'] = 'nalog';
            $this->data['podstrana'] = 'novi-nalog';
            $this->data['drzave'] = $this->nalog->listaj_drzave();
            $this->navigate($this->data['strana'].'/'.$this->data['podstrana']);
        }
        function kreiraj_nalog(){

            $response = $this->nalog->provjeri_podatke_naloga();   
            if($response['success'] == 'success') {   
                // create a new user
                if($this->simple_login_secure->create(FALSE)){    //AUTOLOGIN = FALSE
                    $this->get_encode(array('success'=>'success','message'=>'Nalog uspesno kreiran.'));
                }else{
                    $this->get_encode(array('success'=>'failed','message'=>'Nesto nije u redu prilikom kreiranja naloga.'));
                }  

            }else {
                $this->get_encode(array('success'=>'failed','message'=>$response['message']));
            }
        }
        function get_encode($array){
            echo $_GET['jsoncall'] . '(' . json_encode($array) . ');';
        }
        function lista_naloga(){
            if ($this->session->userdata('logged_in') != TRUE)
            {
                redirect(base_url().'login');
            }
            $this->data['strana'] = 'nalog';
            $this->data['podstrana'] = 'home';
            $this->data['nalozi'] = $this->nalog->listaj_naloge();
            $this->navigate($this->data['strana'].'/'.$this->data['podstrana']);
        }
        function uredba_naloga($id){
            if ($this->session->userdata('logged_in') != TRUE)
            {
                redirect(base_url().'login');
            }
            $this->data['strana'] = 'nalog';
            $this->data['podstrana'] = 'uredi-nalog';
            $this->data['nalozi'] = $this->nalog->listaj_nalog($id);
            $this->navigate($this->data['strana'].'/'.$this->data['podstrana']);
        }
        function prijavna_forma(){
            $this->data['drzave'] = $this->nalog->listaj_drzave();
            $html = $this->load->view('nalog/prijavna-forma', $this->data, TRUE);
            $this->get_encode(array('html' => $html));
        }
        function planovi_cene(){
            if ($this->session->userdata('logged_in') != TRUE)
            {
                redirect(base_url().'login');
            }
            $this->data['strana'] = 'nalog';
            $this->data['podstrana'] = 'planovi_cene';
            $this->carabiner->css('planovi_cene.css');
            $this->navigate($this->data['strana'].'/'.$this->data['podstrana']);
        }
    }
?>
